


<?
	  layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
<div class="col-lg-4">
	<div class="panel" style="height: 400px; overflow: auto;">
		<div class="panel-heading">字典项管理</div>
			
		<div class="panel-body">
			<ul id="tree" class="ztree" style="width:300px"; overflow:auto;">
				
			</ul>
		</div>
		
	</div>
</div>
<?} ?>
<script>
	var dictId = window.parent.getdictIdZTree();			//所属  字典类Id
	var oncliDataId = window.parent.getoncliDataId();			//所属  字典类Id
	
	//树状结构
	$(function() {
		/* initTree(); */
		loadOneTree();
	});
	/* function initTree() {
		$.ajax({
			type : "post",
			data : {
				"dictId" : dictId
			},
			url : "./findallDictItemZTree.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}

	function drawTree(data) {
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : false
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], true);//指定某节点折叠

	} */
	
	var treeSetting = {
		async: {
			enable: true, url:"./findallDictItemZTreeAsy.do",
			dataType:"json",
			autoParam:["id","dictId","value","level"]
		},
		view: {
		dblClickExpand: true,
		selectedMulti: false,
		expandSpeed: ($.browser.msie && parseInt($.browser.version)<=6)?"":"fast"
		},
		data: {
		  simpleData: {
		    enable:true
		  }
		},
		callback: {
			onClick : onClick
		 /*  beforeExpand: beforeExpand */
		}
	};
	
	function loadOneTree(){
		$.ajax({
			type: "post",
			url: "loadOneTree.do",
			data: {
				"dictId": dictId
			},
			dataType: "json",
			success: function(data) {
				if(data[0].msg=="OK"){
					loadTree(data[0].data);
				}else{
					alert("请求失败");
				}
			},
			error : function(data) {
				// alert("请求失败");
			}
		});
	}
	
	function loadTree(rootNode){
		var zTreeObj = $.fn.zTree.init($("#tree"), treeSetting, rootNode);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], false);//指定某节点折叠
	}
	var saveid;
	var savename;
	function onClick(e, treeId, treeNode) {
		saveid = treeNode.value;		//获取点击  树形 ID
		savename=treeNode.name;  //获取点击 树形 name
	}
	
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	
	function qingling(){
		parent.$("#dictitemId").val("0");
	    parent.$("#dictitemName").val("根节点");
	    parent.layer.tips("Ok", "#xuanze", {time: 5000});
		parent.layer.close(index);
	}
	function queren(){
			if(saveid==null){
					parent.$("#dictitemId").val("0");
				    parent.$("#dictitemName").val("根节点");
					parent.layer.close(index);
					
				}else{
					parent.$("#dictitemId_"+oncliDataId).val(saveid);
				    parent.$("#dictitemName_"+oncliDataId).val(savename);
				    parent.$("#dictId").val(dictId);
				   	parent.layer.tips("Ok", "#t_"+oncliDataId, {time: 5000});
					parent.layer.close(index);
				}
	}
	
	
</script>



